package com.globallogic.dailyplanner.repository;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.globallogic.dailyplanner.dto.DailyPlan;

public interface DailyPlanRepository extends JpaRepository<DailyPlan, Integer>{
	@Query("SELECT dailyplan from DailyPlan dailyplan WHERE dailyplan.user.id = :id")
	List<DailyPlan> findById(@Param("id") int id);
	
	@Query("SELECT dailyplan FROM DailyPlan dailyplan WHERE dailyplan.activity = :name "
			+ "AND dailyplan.date = :startDate AND dailyplan.estimateDuration = :estimateDuration")
	DailyPlan findByNameAndTime(@Param("name") String name,
								@Param("startDate") Date startDate,
								@Param("estimateDuration") String estimateDuration);
	
	@Query("SELECT dailyplan FROM DailyPlan dailyplan WHERE dailyplan.date BETWEEN :startDate AND :endDate")
	List<DailyPlan> findAllByDate(@Param("startDate") Calendar startDate, @Param("endDate") Calendar endDate);
}
